﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApMovDirectXVideoWrapper
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Windows.Forms;


namespace DnProcessSimulateCommands;

internal class CApMovDirectXVideoWrapper : IDisposable
{
  private object m_video;
  private CApMovMovieManagerDxPlay m_play;
  private Control m_owner;

  internal CApMovDirectXVideoWrapper(Control owner, string filePath)
  {
    this.m_owner = owner;
    this.CreateVideo(filePath);
  }

  internal void CreateVideo(string filePath) => this.ConditionalCreateVideo(filePath);

  internal CApMovMovieManagerDxPlay PlayManager
  {
    get => this.m_play;
    set => this.m_play = value;
  }

  internal double CurrentPosition
  {
    get
    {
      double currentPosition = 0.0;
      this.ConditionalCurrentGetPosition(ref currentPosition);
      return currentPosition;
    }
    set => this.ConditionalCurrentSetPosition(value);
  }

  public double Duration
  {
    get
    {
      double duration = 0.0;
      this.ConditionalGetDuration(ref duration);
      return duration;
    }
  }

  public Control Owner
  {
    get
    {
      Control owner = (Control) null;
      this.ConditionalGetOwner(ref owner);
      return owner;
    }
    set => this.ConditionalSetOwner(value);
  }

  public bool Playing
  {
    get
    {
      bool playing = false;
      this.ConditionalGetPlaying(ref playing);
      return playing;
    }
  }

  public void RegisterEnding(CApMovMovieManagerDxPlay.DxPlayEvent handler)
  {
    this.ConditionalAddEnding(handler);
  }

  public void UnRegisterEnding(CApMovMovieManagerDxPlay.DxPlayEvent handler)
  {
    this.ConditionalRemoveEnding(handler);
  }

  public void Pause() => this.ConditionalPause();

  public void Play() => this.ConditionalPlay();

  public void Stop() => this.ConditionalStop();

  public void DisposeVideo() => this.ConditionalDisposeVideo();

  internal void Resize()
  {
    if (this.m_play == null)
      return;
    this.m_play.ResizeVideoWindow();
  }

  private void ConditionalCreateVideo(string filePath)
  {
    if (this.m_play != null)
      this.m_play.Dispose();
    this.m_play = new CApMovMovieManagerDxPlay(this.m_owner, filePath);
  }

  private object DirectXVideo
  {
    get => this.m_video;
    set => this.m_video = value;
  }

  private void ConditionalCurrentGetPosition(ref double currentPosition)
  {
    currentPosition = this.PlayManager.Position;
  }

  private void ConditionalCurrentSetPosition(double currentPosition)
  {
    this.PlayManager.Position = currentPosition;
  }

  private void ConditionalGetDuration(ref double duration) => duration = this.PlayManager.Duration;

  private void ConditionalGetOwner(ref Control owner) => owner = this.m_owner;

  private void ConditionalSetOwner(Control owner) => this.m_owner = owner;

  private void ConditionalGetPlaying(ref bool playing) => playing = this.PlayManager.Playing;

  private void ConditionalAddEnding(
    CApMovMovieManagerDxPlay.DxPlayEvent DirectXVideo_Ending)
  {
    this.PlayManager.StopPlay += new CApMovMovieManagerDxPlay.DxPlayEvent(DirectXVideo_Ending.Invoke);
  }

  private void ConditionalRemoveEnding(
    CApMovMovieManagerDxPlay.DxPlayEvent DirectXVideo_Ending)
  {
    this.PlayManager.StopPlay -= new CApMovMovieManagerDxPlay.DxPlayEvent(DirectXVideo_Ending.Invoke);
  }

  private void DirectXVideo_Ending(object sender, EventArgs e)
  {
    int num = (int) MessageBox.Show("Ending");
  }

  private void ConditionalPause() => this.PlayManager.Pause();

  private void ConditionalPlay() => this.PlayManager.Start();

  private void ConditionalStop() => this.PlayManager.Stop();

  private void ConditionalDisposeVideo() => this.PlayManager.Dispose();

  public void Dispose() => this.ConditionalDisposeVideo();
}
